const getDefaultState = () => {
  return {
    formType: "login",
    SaaSformType: "login",
    regionId: "",
    cardType: 28,
    personId: "",
    uid: "",
    role: "teacher",
    showLoginDialog: false,
  };
};

const state = getDefaultState();

const mutations = {
  SET_FORM_TYPE: (state, formType) => {
    state.formType = formType;
  },
  SET_SAASFORM_TYPE: (state, SaaSformType) => {
    state.SaaSformType = SaaSformType;
  },

  SET_ROLE: (state, role) => {
    state.role = role;
  },

  SET_REGION_ID: (state, regionId) => {
    state.regionId = regionId;
  },
  SET_CARD_TYPE: (state, cardType) => {
    state.cardType = cardType;
  },
  SET_PERSON_ID: (state, personId) => {
    state.personId = personId;
  },
  SET_UID: (state, uid) => {
    state.uid = uid;
  },
  SET_SHOW_LOGIN_DIALOG: (state, val) => {
    state.showLoginDialog = val;
  },
};

const actions = {
  setFormType({ commit }, formType) {
    commit("SET_FORM_TYPE", formType);
  },
  setSaaSFormType({ commit }, SaaSformType) {
    commit("SET_SAASFORM_TYPE", SaaSformType);
  },
  setRole({ commit }, role) {
    commit("SET_ROLE", role);
  },
  setRegionId({ commit }, regionId) {
    commit("SET_REGION_ID", regionId);
  },
  setCardType({ commit }, cardType) {
    commit("SET_CARD_TYPE", cardType);
  },
  setPersonId({ commit }, personId) {
    commit("SET_PERSON_ID", personId);
  },
  setUid({ commit }, uid) {
    commit("SET_UID", uid);
  },
  setShowLoginDialog({ commit }, val) {
    commit("SET_SHOW_LOGIN_DIALOG", val);
  },
  checkLogin({ commit }) {
    if (localStorage.token) {
      commit("SET_SHOW_LOGIN_DIALOG", false);
      return true;
    } else {
      commit("SET_SHOW_LOGIN_DIALOG", true);
      return false;
    }
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
